import Taro from '@tarojs/taro'
import {
    UPDATA_USERINFO,
    IS_USERINFO
} from './action-types'

interface UserInfo{
    avatarUrl?: string
    mobile: string
    accessId: string
    accessKey: string
    userId: number
    serverTime?: number
    nickname?: string
    sex?: number
}

interface State {
    userInfo: UserInfo
    routesBack: string
    // 用户首次加载进入页面记录
    firstRouter: string
}

const INITIAL_STATE: State = {
    userInfo: Taro.getStorageSync(IS_USERINFO) || {},
    routesBack: '',
    firstRouter: ''
}
export default function user(state = INITIAL_STATE, action) {
    switch (action.type) {
        case UPDATA_USERINFO:
            return {
                ...state,
                userInfo: action.userInfo
            }
        default:
            return state
    }
}